Skip to content

[Repo Assist] feat: add map, filter, iter, exists, forall, toList, toArray to Queue and Deque#241

Open
github-actions[bot] wants to merge 7 commits intomasterfrom
repo-assist/improve-queue-deque-functions-20260310-abe469ac1b3fa769
Open

[Repo Assist] feat: add map, filter, iter, exists, forall, toList, toArray to Queue and Deque#241
github-actions[bot] wants to merge 7 commits intomasterfrom
repo-assist/improve-queue-deque-functions-20260310-abe469ac1b3fa769

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This PR was created by Repo Assist, an automated AI assistant.

Adds seven commonly used collection functions to the Queue and Deque modules. Partially addresses #152 (Align Collection Module functions with FSharp.Collections).

Changes

New functions (Queue and Deque)

Function Complexity Description
map f q O(n) Transform each element, returning a Queue/Deque
filter pred q O(n) Keep only elements satisfying the predicate
iter f q O(n) Apply a side-effecting function to each element (FIFO order)
exists pred q O(n) Test whether any element satisfies a predicate
forall pred q O(n) Test whether all elements satisfy a predicate
toList q O(n) Convert to list in FIFO order
toArray q O(n) Convert to array in FIFO order

All functions preserve FIFO element order. Signatures added to .fsi files. 21 new tests added.

Implementation notes

Queue.map directly maps over the internal front and rBack lists, preserving the queue structure without any rebuilding — very efficient.

Queue.filter handles the invariant that front should not be empty for a non-empty queue: if filtering removes all front elements, List.rev rBack becomes the new front.

Deque.map similarly maps directly over both internal lists. Deque.filter is simpler since Deque tolerates an empty front (it falls back to rBack).

exists and forall can check rBack in any order (order only matters for iter, toList, toArray).

Test Status

All 731 tests pass (6 pre-existing ptest skips unrelated to this PR):

Passed! - Failed: 0, Passed: 731, Skipped: 6, Total: 737

Generated by Repo Assist ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@346204513ecfa08b81566450d7d599556807389f

… and Deque modules

Adds commonly needed collection functions to Queue and Deque that
were present in F# List but missing from these modules. Addresses
part of #152 (Align Collection Module functions with FSharp.Collections).

New functions for both Queue and Deque:
- map       : transform each element, returning the same collection type
- filter    : keep elements matching a predicate
- iter      : apply a side-effecting function to each element (FIFO order)
- exists    : test whether any element satisfies a predicate
- forall    : test whether all elements satisfy a predicate
- toList    : convert to list in FIFO order
- toArray   : convert to array in FIFO order

All seven functions are O(n) and preserve FIFO element order.
21 new tests added (QueueTest and DequeTest), all passing.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
github-actions bot added a commit that referenced this pull request Mar 13, 2026
… tests

Adds six new module-level functions to DList, mirroring the functions
added to Queue and Deque in #241, and further addressing #152.

- DList.map: transforms all elements using a function
- DList.filter: retains elements matching a predicate
- DList.iter: applies an action to each element in order
- DList.exists: short-circuit check if any element matches
- DList.forall: short-circuit check if all elements match
- DList.toArray: returns elements as an array

map and filter are implemented via foldBack so they build a DList
directly (preserving the length invariant). iter/exists/forall/toArray
delegate to the IEnumerable<'T> implementation for correct short-circuit
behaviour.

Also adds 21 new tests: 14 unit tests and 7 property-based tests that
verify results match standard List/Array equivalents.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@gdziadkiewicz gdziadkiewicz self-assigned this Mar 14, 2026
@gdziadkiewicz gdziadkiewicz requested review from Copilot and gdziadkiewicz and removed request for Copilot March 14, 2026 13:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds FSharp.Collections-aligned collection helpers to Queue and Deque, expanding their module APIs with common traversal/transformation/conversion functions while preserving the collections’ logical ordering.

Changes:

  • Added toList, toArray, map, filter, iter, exists, forall to Queue and Deque implementations.
  • Exposed the new functions in the corresponding .fsi signature files.
  • Added unit tests covering the new APIs (order preservation and basic semantics).

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/FSharpx.Collections/Queue.fs Implements the seven new Queue module functions.
src/FSharpx.Collections/Queue.fsi Adds public signatures/docs for the new Queue functions (also includes spacing/formatting changes).
src/FSharpx.Collections/Deque.fs Implements the seven new Deque module functions.
src/FSharpx.Collections/Deque.fsi Adds public signatures/docs for the new Deque functions (also includes spacing/formatting changes).
tests/FSharpx.Collections.Tests/QueueTest.fs Adds tests for new Queue APIs (FIFO order and basic behavior).
tests/FSharpx.Collections.Tests/DequeTest.fs Adds tests for new Deque APIs (order and basic behavior).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread src/FSharpx.Collections/Queue.fs
Comment thread src/FSharpx.Collections/Queue.fs
Comment thread src/FSharpx.Collections/Deque.fs
Comment thread src/FSharpx.Collections/Deque.fs
Comment thread src/FSharpx.Collections/Queue.fsi
Comment thread src/FSharpx.Collections/Deque.fsi
Comment thread tests/FSharpx.Collections.Tests/DequeTest.fs
@dsyme dsyme marked this pull request as ready for review March 16, 2026 13:45
@gdziadkiewicz
Copy link
Copy Markdown
Collaborator

@copilot resolve the confilts too

@gdziadkiewicz
Copy link
Copy Markdown
Collaborator

@copilot resolve the merge conflicts in this pull request

…t test

Co-authored-by: gdziadkiewicz <8547855+gdziadkiewicz@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 19, 2026

@copilot resolve the merge conflicts in this pull request

Resolved in c2a93a4 — merged master into the branch, resolving conflicts in Queue.fsi and Deque.fsi by keeping our new function signatures.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds common collection-style operations to Queue and Deque to better align with FSharp.Collections, including public signatures and accompanying tests.

Changes:

  • Added toList, toArray, map, filter, iter, exists, and forall to Queue and Deque modules.
  • Updated .fsi files with the new public API surface and XML docs.
  • Added unit tests covering the new operations.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
tests/FSharpx.Collections.Tests/QueueTest.fs Adds tests for new Queue functions.
tests/FSharpx.Collections.Tests/DequeTest.fs Adds tests for new Deque functions.
src/FSharpx.Collections/Queue.fsi Exposes new Queue functions in the public signature.
src/FSharpx.Collections/Queue.fs Implements new Queue functions.
src/FSharpx.Collections/Deque.fsi Exposes new Deque functions in the public signature.
src/FSharpx.Collections/Deque.fs Implements new Deque functions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/FSharpx.Collections/Deque.fs
Comment thread tests/FSharpx.Collections.Tests/DequeTest.fs Outdated
Comment thread tests/FSharpx.Collections.Tests/QueueTest.fs
Comment thread tests/FSharpx.Collections.Tests/DequeTest.fs Outdated
Comment thread src/FSharpx.Collections/Deque.fsi Outdated
Comment thread src/FSharpx.Collections/Deque.fsi Outdated
Comment thread src/FSharpx.Collections/Deque.fs Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
gdziadkiewicz and others added 2 commits April 19, 2026 14:23
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…enumeration) order

Agent-Logs-Url: https://github.com/fsprojects/FSharpx.Collections/sessions/5eadd029-f378-41de-ae25-5542f541bada

Co-authored-by: gdziadkiewicz <8547855+gdziadkiewicz@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1233 to +1236
test "toArray preserves FIFO order" {
let q = Deque.ofSeq [ 1; 2; 3 ] |> Deque.conj 4 |> Deque.conj 5
Expect.equal "toArray" [| 1; 2; 3; 4; 5 |] (Deque.toArray q)
}
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test name uses “FIFO order”, but for Deque the relevant semantic is “front-to-back (enumeration) order”. Consider renaming this (and the similar map/iter tests below) to avoid implying FIFO-specific behavior.

Copilot uses AI. Check for mistakes.
Comment on lines +350 to +353
test "filter keeps matching elements" {
let q = Queue.ofSeq [ 1; 2; 3; 4; 5; 6 ]
Expect.equal "filter even" [ 2; 4; 6 ] (Queue.filter (fun x -> x % 2 = 0) q |> Queue.toList)
}
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Queue.filter has special logic to rebuild front from rBack when filtering removes all front elements. There’s no test exercising that front-empty/rear-nonempty path (e.g., build a queue where front is fully filtered out but rBack retains matches) — adding one would better protect this invariant-handling behavior.

Copilot uses AI. Check for mistakes.
let q = Deque.ofSeq [ 1; 2; 3 ] |> Deque.conj 4 |> Deque.conj 5
Expect.equal "toArray" [| 1; 2; 3; 4; 5 |] (Deque.toArray q)
}

Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deque.toArray is introduced here but the tests don’t cover the empty deque case (expected [||]). Adding an empty-input test would align with the Queue coverage and guard against regressions in the edge case.

Suggested change
test "toArray empty deque" { Expect.equal "toArray empty" [||] (Deque.toArray Deque.empty) }

Copilot uses AI. Check for mistakes.
Comment on lines +1249 to +1252
test "filter keeps matching elements" {
let q = Deque.ofSeq [ 1; 2; 3; 4; 5; 6 ]
Expect.equal "filter even" [ 2; 4; 6 ] (Deque.filter (fun x -> x % 2 = 0) q |> Deque.toList)
}
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deque.filter is only tested on a deque built from ofSeq (so rBack is empty). Add a test where the deque has elements in rBack (e.g., via conj) to validate filtering preserves front-to-back order across the internal front/rear split.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants